/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package votingkeypair;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;

/**
 *
 * @author Maciek
 */
public class VotingKeyPair {

    /**
     * @param args the command line arguments
     */
    
    public static String publicKeyFile = "public.key";
    public static String privateKeyFile = "private.key";
    
    public static void generateAndSavePublicPrivateKey(){
        try {
            GenerateKeysAndSecret gkas = new GenerateKeysAndSecret();
            gkas.generateKeys(1024);
            gkas.storeKeysX509("keys", 30, 3, 4, "keys" + File.separatorChar + "secret");
            
            System.out.println("#####Zapisałem");
            int[] ids = {1,3,4};
            gkas.restoreKeysX509("keys", 3, ids, "keys" + File.separatorChar + "secret");
        } catch (InvalidKeySpecException ex) {
            Logger.getLogger(VotingKeyPair.class.getName()).log(Level.SEVERE, null, ex);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(VotingKeyPair.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(VotingKeyPair.class.getName()).log(Level.SEVERE, null, ex);
        } catch (BadPaddingException ex) {
            Logger.getLogger(VotingKeyPair.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InterruptedException ex) {
            Logger.getLogger(VotingKeyPair.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(VotingKeyPair.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public static void main(String[] args) {
        generateAndSavePublicPrivateKey();
     /*   try {
            // TODO code application logic here
            
            GenerateKeysAndSecret gkas = new GenerateKeysAndSecret();
            gkas.generateKeys(1024);
            gkas.checkWritingToFiles();
            gkas.checkCommunication();
            
            ShamirsSecret ss = new ShamirsSecret();
           // int ret = ss.splitShamirSecret("\'MalySekrecikMaciusia\'", 2, 3);
            //ss.showSecrets();
              int ret = ss.fileShamirSecret("keys" + File.separatorChar + "secret", "BiczesBeCrazyAndVeryWrongMyDearFriend", 2 ,3);
              ss.showSecrets();
              
              int[] ids = {1,2};
              
              ss.fileCombineShamirSecret("keys" + File.separatorChar + "secret", 2, ids);
              
              System.out.println("Tajemnica " + ss.getSecret());
              ids[0]=2 ; ids[1] = 3;
              
              ss.fileCombineShamirSecret("keys" + File.separatorChar + "secret", 2, ids);
              System.out.println("Tajemnica " + ss.getSecret());
              
        } catch (InterruptedException ex) {
            Logger.getLogger(VotingKeyPair.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NoSuchPaddingException ex) {
            Logger.getLogger(VotingKeyPair.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InvalidKeyException ex) {
            Logger.getLogger(VotingKeyPair.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalBlockSizeException ex) {
            Logger.getLogger(VotingKeyPair.class.getName()).log(Level.SEVERE, null, ex);
        } catch (BadPaddingException ex) {
            Logger.getLogger(VotingKeyPair.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InvalidKeySpecException ex) {
            Logger.getLogger(VotingKeyPair.class.getName()).log(Level.SEVERE, null, ex);
        }  catch (IOException ex) {
            Logger.getLogger(VotingKeyPair.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(VotingKeyPair.class.getName()).log(Level.SEVERE, null, ex);
        }*/
    }
        
}
